#include <iostream>
using namespace std;
unsigned long long ans;
int len;
char ch[100];
void trans()
{
	int i, j;
	for (i = 0, j = len - 1; i < (len / 2); i++, j--)
		swap(ch[i], ch[j]);
}
long long square(int x)
{
	int i;
	long long answer = 1;
	for (i = 0; i < x; i++)
		answer *= 2;
	return answer;
}
void mul()
{
	int i;
	for (i = len - 1; i >= 0; i--)
		ans += (square(i + 1) - 1) * (ch[i] - '0');
}
int main()
{
	while (cin >> ch && (ch[0] - '0'))
	{
		len = strlen(ch);
		ans = 0;
		trans();
		mul();
		cout << ans << endl;
	}
	return 0;
}